<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ include file="/WEB-INF/component/commonTagLib.jsp" %> 
<!DOCTYPE html>
<html>
<head>
	<title>药品导入管理</title>
	<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
    .box-body{
    margin-top:-2px;
    }    	
    </style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>药品导入文件</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">目录管理</a></li>
            <li class="active"><a href="#">药品导入文件管理</a></li>
        </ol>
    </section>
    
    <section class="content">
      <form id="form" method="post" class="form-horizontal">    
        <div class=" box box-success">
            <div class="box-body">
               <div class="input">
                    <div class="textalign1">文件名：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="fileName" name="fileName" placeholder="文件名" />
                    </div>
                    
                    <div class="textalign1" >上传日期：</div>
                    <div class="boxinput"> 
                        <table style="width:100%;">
                                <tr>
                                    <td style="width:50%">       
                                        <input class="textinput" type="text" name="starttime" id="starttime"
						                   placeholder="yyyy-MM-dd" 
						                   onFocus="var endDate=$dp.$('endtime');WdatePicker({maxDate:'#F{$dp.$D(\'endtime\')}'})"/>
						            </td>
                                    <td>&nbsp;-&nbsp;</td>
                                    <td style="width:50%">       
                                        <input class="textinput" type="text" name="endtime" id="endtime"
						                   placeholder="yyyy-MM-dd" 
						                    onFocus="WdatePicker({minDate:'#F{$dp.$D(\'starttime\')}'})"/>
                                    </td>
                                </tr>
                         </table>        
                    </div>        
                    <div class="textalign1">状态：</div>
                    <div class="boxinput">
                    <select class="textinput" id="status" name="status">
                    	<option value="">请选择</option>
                    	<c:forEach items="${fileStatus}" var="fs">
                    		<option value="${fs.key}">${fs.value}</option>
                    	</c:forEach>
                    </select>
                    </div>
                    <div class="textalign" >
                       <button    id="selectSerch"    type="button"  onclick="gridSerch()"  class="btn btn-success btn-sm">查&nbsp;询</button>
                    </div>
               </div>
               <div class="input" style="margin-left:90px;">
               <div class="boxinput">
               	<select class="textinput" id="reTime" onchange="refreshInfo()">
               		<option value="">不刷新</option>
               		<option value="10">10秒刷新一次</option>
               		<option value="20">30秒刷新一次</option>
               		<option value="60">1分钟刷新一次</option>
               	</select>
               	</div>
               </div>
               
             
            </div>
           </div>
        </form> 
        <table class="jqgrid" id="gridlist"></table>
        <div id="prowed2"></div>
		 <div class=" box box-warning bottongroup">
		 <a href="javascript:void(0);" class="btn btn-default btn-sm"  onclick="importFile()">导入文件上传</a>
		 <a href="${ctx }/bidProject/downloadModel.html" class="btn btn-default btn-sm">模板下载</a>
	         <a href="${ctx}/bidProject/toPurUnBidProjectDrugsList.html?projId=${projId}" class="btn btn-default btn-sm" >返 回</a>
        </div>
                        <div class="form-group form-group-xs">
                                <table class="jqgrid col-sm-1" id="gridlist1"></table>
        <div id="gridpage1 col-sm-1"></div>
                            </div>
                      
	<table class="jqgrid" id="gridlist"></table>
<div style="margin-top: 10px;"></div>
	<form action="${ctx}/stdCompinfo/toStdCompinfoDetailJsp.html"
		id="FormDetail" method="post">
		<input type="hidden" name="compCodeDetail" id="compCodeDetail" /> 
	</form>
	
	
	
	 <!-- 批量导入 -->
            <div class="modal fade" id="batchImport" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-primary">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h5 class="modal-title" id="exampleModalLabel">导&nbsp;入</h5>
                    </div>
                    
                    
                    <div class="modal-body">
                        <form name="importform" id="importform" method="post" action="${ctx }/bidProject/bathImportView.html?projId=${projId}" enctype="multipart/form-data">
                        <input type="hidden" name="projId" id="projId" value="${projId}" />
                            <div class="form-group form-group-xs">
                                <label for="recipient-name" class="control-label">导入文件:</label>
                                <input type="file" name="drugFile" id="drugFile"/>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" onclick="bathImport();" class="btn btn-primary btn-sm">导入</button>
                        <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal">关闭</button>
                        
                    </div>
                </div>
            </div>
        </div>
	
</section>
<%@ include file="/WEB-INF/component/commonJS.jsp"%>
<script type="text/javascript">
function importFile(){
	$("#drugFile").val("");
	$('#batchImport').modal({
        keyboard: true
    });
}
function bathImport(){
	var fileName = $.trim($("#drugFile").val());
	if (fileName == ""){
		$.HN.message.alert("请选择导入文件！", "消息", "error");
		return;
	}
	$("#importform").submit();
}
$('#importform').ajaxForm({ 
    dataType: 'json', 
    
	success: function(returnData) {
	if(returnData.success) {
		$.HN.message.alert('导入成功！', '提示信息', 'success');
		$("#batchImport").modal("hide");
		gridSerch();
	}else{
		$.HN.message.alert('添加失败，请重新添加！', '提示信息', 'success');
	}
   } 	
});


function refreshInfo(){
	var time = $("#reTime").val();
	var t;
	if (time.length > 0){
		gridSerch();
		t = setTimeout("refreshInfo()", time * 1000);
	} else {
		clearTimeout(t);
	}
}
		
		$(function () {
			
			 //加载页面光标在名字框内，位于第一个
			   $("#fileName").focus();
			   
			 //绑定回车     id="selectSerch"   
			   $('#fileName,#starttime,#endtime,#status').bind('keydown', function(event) {
			       if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
			           $('#selectSerch').click();
			       }
			   }); 	
			
		jQuery("#gridlist").jqGrid({
			url: "${ctx}/bidProject/getImportFileDataList.html?projId=${projId}",
		    mtype: "POST",
			datatype: "json",
			autowidth: true,
			shrinkToFit:true,
			height: 270,
		   	colNames:[
		   	          '操作',
		   	          'Id',
		   	          '原始文件名',
		   	          '上传人',
		   	          '上传时间',
		   	          '状态'
		   	          ],
		   	colModel:[
                {name:'oper',index:'oper', width:100, align:"center",sortable:false,
		            formatter : function(val, opts, rowdata) {
			        var str = "";
			         if (rowdata.status == "未校验"){
			        	 
			         } else{
			         		if (rowdata.status == "校验通过" || rowdata.status == "校验不通过"){
			         			str = "<a href=\"${ctx}/bidProject/toImoprtDrugView.html?fileId="+rowdata.fileId+"&projId=${projId}\">导入预览</a>";
	              			}
			         		if (rowdata.status!="校验中" && rowdata.status!="校验异常"){
			         			str += "<a href=\"${ctx}/bidProject/downloadResult.html?fileId="+rowdata.fileId+"\" >执行结果查看</a>";
			         		}
			         }
			          return str;
			          }
                },
				{name:'fileId',index:'fileId',hidden:true, width:100,align:"center", sorttype:false,sortable:false
				},
				{name:'fileName',index:'fileName', width:140, align:"center",sorttype:false,sortable:false},
		   		{name:'upUser',index:'upUser', width:100,align:"left", sorttype:false,sortable:false},
		   		{name:'upTime',index:'upTime', width:80, align:"center"},
		   		{name:'status',index:'status', width:80, align:"left",sorttype:false,sortable:false}
		   	],
			 rowNum: 20,
		     rowList: [10, 20, 50, 100],
		     rownumbers: true,
		     multiselect: false,
		     pager: "#prowed2",
		     viewrecords: true,
		     caption: "${projName}--药品导入文件列表",
		   //序号宽度自动变化
             gridComplete:function(){
                 //序号列宽度自适应（参数为jqgridID）
                 autoRNWidth("gridlist");
                 //数据只有一条时默认选中（参数为jqgridID）
                 selectByOneData("gridlist");
             },
		     editurl:"proPlanItemListHis.jsp",
		     jsonReader: {
		         repeatitems: false,
		         id: "goodsCode"
		     }
		   	
		});
			 
			jQuery("#gridlist").jqGrid('navGrid',"prowed2",{edit:false,add:false,del:false});
			$(window).trigger("resize");
			$("#gridlist").jqGrid("setGridHeight", create());
			
			$("#drugCat").HNSelect({
		        url: "${pageContext.request.contextPath}/selectController/getDicSys.html", data: { ID: '115' },defaultselect:'${form.patternType}',  defaultText: "<option value=''>请选择</option>",
		    });
		});
		
		function gridSerch() {
			var fileName = $.trim($("#fileName").val());
			var starttime = $.trim($("#starttime").val());
			var endtime = $.trim($("#endtime").val());
			var status = $.trim($("#status").val());
			$("#gridlist").jqGrid('setGridParam',{  
		        datatype:'json',
		        postData:{"fileName":fileName,
		        		"starttime":starttime,
		        		"endtime":endtime,
		        		"status":status},
		        		page:1
		    }).trigger("reloadGrid"); //重新载入  
		}
		
		function reImport(fileId){
			$.ajax({
                url: "${pageContext.request.contextPath}/bidOtherProject/reImport.html",//action地址
                data: { fileId:fileId },//传值
                type: "post",//执行方式get or post 默认以post方式执行
                dataType:"json",
                success: function (result) {//执行成功后 提示
                    if (result.success){
                    	$.alert("正在执行", "success");
                	   gridSerch($("#gridlist").jqGrid('getGridParam','page'));
                   } else {
                	   $.alert("", "error");
                   } 
                }
            });
		}
		    
		    function stop(){
		    	var checked = false;
		    	 $("input.cbox").each(function() {
		    	     if($(this).is(":checked")) {
		    	    	 checked = true;
		    	    	 return false;
		    	     };
		    	 });
		    	 
		    	 if (!checked) {
		    		 $.HN.message.alert('请选择要停用的条目', '提示信息', 'failed');
		    	 }else{
		   	 $.HN.message.confirm("确定要停用吗？", '', '').on(function (e) {
		           if (e) {
		               $.HN.message.alert('操作成功！', '提示信息', 'success');
		               window.location.href="onSellDrugListCenter.jsp";
		               
		           }
		       });
			   
		       }
		    }
		   $("#allDelete1").click(function(){
			   var checked = false;
		   	 $("input.cbox").each(function() {
		   	     if($(this).is(":checked")) {
		   	    	 checked = true;
		   	    	 return false;
		   	     };
		   	 });
		   	 
		   	 if (!checked) {
		   		 $.HN.message.alert('请选择要启用的条目', '提示信息', 'failed');
		   	 }else{
		     	 $.HN.message.confirm("确定要启用吗", '', '').on(function (e) {
		              if (e) {
		                  $.HN.message.alert('操作成功！', '提示信息', 'success');
		                  window.location.href="onSellDrugListCenter.jsp";
		                  
		              }
		          });
		   	 }
		     });
		   
			function goJsp(n1){
				
				var opt ={
						url:"../../jsp/price/priceChangeExeDetailGrid.jsp",
						title:"newwindow",
		style:{height:400,width:890,top:200,left:270}
				};
				$.HN.dialog.open(opt);
				
		}    
		    function selectComp(){
		 	   
		 		$("#compCode").val("");
		 	    $("#compName").val("");
		 	 gridCompSerch();
		 	   $('#selectComp').modal({
		 			keyboard : true
		 		});
		 	   
		 	  // window.open("${pageContext.request.contextPath}/stdDrug/toSelectComp.html?value=prodPompId&text=comp","newwin","dialogHeight: 200px; dialogWidth: 150px; dialogTop: 458px; dialogLeft: 166px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: Yes;");
		    }
		    function gridCompSerch() {
		    	var compCode = $("#compCode").val();
		    	var compName = $("#compName").val();
		 		$("#gridlist1").jqGrid('setGridParam',{  
		 	        datatype:'json',
		 	        postData:{"compCode":compCode,
		 	        		"compName":compName}
		 	    }).trigger("reloadGrid"); //重新载入  
		 	}
		    function gridOk(){
		 	   var compId = $("#gridlist1").jqGrid('getGridParam', 'selrow');
		        if (compId == null) {
		     	   $.HN.message.alert('请至少选一行！', '提示信息', 'error');
		            return;
		        }
		        var rowdata = $("#gridlist1").jqGrid('getRowData', compId);
		        $("#prodPompId").val(compId);
		        $("#comp").val(rowdata.compName);
		        $("#selectComp").modal("hide");
		        
		    }
		    function cleandata(){
		 	   $("#prodPompId").val("");
		        $("#comp").val("");
		        $("#selectComp").modal("hide");
		    }
		    function operResult(val){
		        
		    }
		    function fileUp(){
		    	$('#batchImport').modal({
                    keyboard: true
                });
		    }
</script>
</body>
</html>